
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>制造物联中间件系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">设备管理</a>
            <a href="">设备故障</a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <span class="layui-inline layui-show-xs-block">
                            <select name="type" id="condition">
                                <option value="device_fault_id">设备故障编号</option>
                                <option value="device_id">设备名称</option>

                            </select>
                        </span>
                        <span class="layui-inline layui-show-xs-block">
                            <input type="text" name="searchText" id="conditionName" placeholder="请输入搜索内容"
                                   autocomplete="off"
                                   class="layui-input">
                        </span>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="search" lay-filter="search">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" id="delAll"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn" onclick="xadmin.open('添加用户','./device-fault-add',600,400)"><i class="layui-icon"></i>添加</button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form" id="test" lay-filter="test"></table>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="update">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
</script>


<script type="text/html" id="dn">
    {{#  if( d.device!=null){      }}
    <span id="deviceName" onclick="xadmin.open('设备名称','${pageContext.request.contextPath}/device/update?deviceId='+'{{d.deviceId}}',600,500)" style="color: red">{{d.device.deviceName}}</span>
    {{#  } else { }}
    <div>未命名</div>
    {{#  } }}
</script>


<script type="text/html" id="dfd">
    <div>
        <a onclick="xadmin.open('故障描述','${pageContext.request.contextPath}/device/device/fault/editText/'+'{{d.deviceFaultId}}',600,400)" style="color: cadetblue">故障描述</a>
    </div>
</script>


<script type="text/html" id="check">
    <input type="checkbox" name=""  lay-skin="primary">
</script>

<script>
    layui.use(['laydate','form','table','jquery'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;


        form.on('submit(search)',
            function (data) {
            table.render({
            elem: '#test'
            , url: '${pageContext.request.contextPath}/device/device/fault/search?type=' + data.field.type + '&searchText=' + data.field.searchText  //数据接口
            // 对我们请求过来的数据进行一次预处理
            , parseData(res) {
                if (res.success) {
                    return {
                        "code": 0, //解析接口状态, 等于0代表成功
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list//解析数据列表
                    }
                } else {
                    layer.msg(res.msg);
                    return {
                        "code": res.code, //解析接口状态, 等于0代表成功
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list//解析数据列表
                    }
                }
            },
            request: {
                //页码的参数名称，默认：page，指定了页码的key
                pageName: 'pageNum'
                // 指定了每页容量的key
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true //开启分页
            , cols: [[ //表头
                    {type:'checkbox'},
                {field: 'deviceFaultId', title: '故障编号'},
                // {title: '设备名称',templet:"dn"},
                {title: '设备名称',templet:"#dn"},
                {field: 'deviceFaultDate', title: '故障日期'},
                {field: 'deviceFaultCause', title: '故障原因'},
                {field: 'deviceFaultMaintenance', title: '维修方式'},
                {title: '故障描述',templet:"#dfd"},
                {title: '操作', toolbar: '#barDemo', width: 150}
            ]]
        });
            return false;
    });



        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });


        //批量删除
        table.on('checkbox(test)', function (obj) {
            var checkStatus = table.checkStatus('test');
            console.log(checkStatus)
        })
        $("#delAll").on("click", function () {
            let ids2 = []
            let list = table.checkStatus('test').data;
            for (let i = 0; i < list.length; i++) {
                ids2.push(list[i].deviceFaultId)
            }
            let ids = ids2.join(",")
            console.log(ids)
            $.ajax({
                url:"${pageContext.request.contextPath}/device/device/fault/deleteAll",
                type: "get",
                data: {ids:ids},
                success(res) {
                    if (res.success) {
                        layer.alert("成功", {
                            icon: 1
                        });
                        location.reload()
                    } else {
                        layer.alert("失败", {
                            icon: 6
                        });
                    }
                }
            })
        })


        table.render({
            elem: '#test'
            , url: '${pageContext.request.contextPath}/device/device/fault/list' //数据接口
            // 对我们请求过来的数据进行一次预处理
            , parseData(res) {
                if (res.success) {
                    return {
                        "code": 0, //解析接口状态, 等于0代表成功
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list//解析数据列表
                    }
                } else {
                    layer.msg(res.msg);
                    return {
                        "code": res.code, //解析接口状态, 等于0代表成功
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list//解析数据列表
                    }
                }
            },
            request: {
                //页码的参数名称，默认：page，指定了页码的key
                pageName: 'pageNum'
                // 指定了每页容量的key
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true //开启分页
            , cols: [[ //表头
                {type:'checkbox'},
                {field: 'deviceFaultId', title: '故障编号'},
                {title: '设备名称',templet:"#dn"},
                // {title: '设备名称',templet:function (data){
                //         if(data.device){
                //             return data.device.deviceName
                //         }else {
                //             return ""
                //         }
                //     }},
                {field: 'deviceFaultDate', title: '故障日期'},
                {field: 'deviceFaultCause', title: '故障原因'},
                {field: 'deviceFaultMaintenance', title: '维修方式'},
                {title: '故障描述',templet:"#dfd"},

                {title: '操作', toolbar: '#barDemo', width: 150}
            ]]
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除这行数据吗?', function (index) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/device/device/fault/delete",
                        type: "get",
                        data: {deviceFaultId:obj.data.deviceFaultId},
                        success(res) {
                            console.log(res)
                            if (res.success) {
                                obj.del();
                                layer.close(index);
                            } else {
                                layer.alert("删除失败", {
                                    icon: 6
                                });
                            }
                        }
                    })
                });
            } else if (obj.event === 'update') {
                xadmin.open('编辑用户','${pageContext.request.contextPath}/device/fault/update?deviceFaultId='+obj.data.deviceFaultId,600,600)
            }
        });

    });

    /*用户-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){

            if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

            }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
            }

        });
    }


</script>
</html>
